package com.ayou.eggguard.farm.controller;

import com.ayou.common.utils.PageBean;
import com.ayou.common.utils.Result;
import com.ayou.eggguard.farm.pojo.Vaccine;
import com.ayou.eggguard.farm.pojo.VaccineRecord;
import com.ayou.eggguard.farm.service.VaccineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/vaccine")
public class VaccineController {

    @Autowired
    private VaccineService vaccineService;

    @GetMapping("/getVaccines")
    public Result<PageBean<Vaccine>> getVaccines(Integer pageNum,
                                                 Integer pageSize,
                                                 @RequestParam(required = false) String vaccineNumber){
        PageBean<Vaccine> pb=vaccineService.getVaccines(pageNum,pageSize,vaccineNumber);
        return Result.success(pb);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Vaccine vaccine){
        vaccineService.add(vaccine);
        return Result.success();
    }

    @GetMapping("/delete")
    public Result delete(Integer id){
        vaccineService.delete(id);
        return Result.success();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Vaccine vaccine){
        vaccineService.update(vaccine);
        return Result.success();
    }

    @GetMapping("/getVaccineRecordList")
    public Result<PageBean<VaccineRecord>> getVaccineRecordList(Integer vpageSize,
                                                                Integer vpageNum,
                                                                String coopNumber){
        PageBean<VaccineRecord> pb=vaccineService.getVaccineRecordList(vpageSize,vpageNum,coopNumber);
        return Result.success(pb);
    }
}
